using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VVUMSV
    {
        public DataRow Convert2VUMSV(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryVUMSV(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["VUVMANDANT"] = " ".PadRight(2 ); 
         dwReturn["VUVRENR"] = " ".PadRight(8 ); 
         dwReturn["VUVREPOS"] = " ".PadRight(3 ); 
         dwReturn["VUVSPLPOS"] = " ".PadRight(4 ); 
         dwReturn["VUVVERTNR"] = " ".PadRight(8 ); 
         dwReturn["VUVKORRKZ"] = " ".PadRight(1 ); 
         dwReturn["VUVDRUCKKZ"] = " ".PadRight(2 ); 
         dwReturn["VUVSPERRKZ"] = " ".PadRight(1 ); 
         dwReturn["VUVPVTYP"] = " ".PadRight(1 ); 
         dwReturn["VUVPVVAR"] = " ".PadRight(1 ); 
         dwReturn["VUVBASISBTR"] = " ".PadRight(0 ); 
         dwReturn["VUVSTDPV"] = " ".PadRight(0 ); 
         dwReturn["VUVSONDPV"] = " ".PadRight(0 ); 
         dwReturn["VUVERSTPV"] = " ".PadRight(0 ); 
         dwReturn["VUVMENGENPV"] = " ".PadRight(11 ); 
         dwReturn["VUVMEEHPV"] = " ".PadRight(3 ); 
         dwReturn["VUVPRNBTL"] = " ".PadRight(0 ); 
         dwReturn["VUVABZUG"] = " ".PadRight(0 ); 
         dwReturn["VUVVPROV"] = " ".PadRight(0 ); 
         dwReturn["VUVABRDAT"] = " ".PadRight(0 ); 
         dwReturn["VUVKUNDNR"] = " ".PadRight(8 ); 
         dwReturn["VUVVB"] = " ".PadRight(3 ); 
         dwReturn["VUVVG"] = " ".PadRight(3 ); 
         dwReturn["VUVABRVON"] = " ".PadRight(0 ); 
         dwReturn["VUVABRBIS"] = " ".PadRight(0 ); 
         dwReturn["VUVFOBBASIS"] = " ".PadRight(1 ); 
         dwReturn["VUVANTEIL"] = " ".PadRight(1 ); 
         dwReturn["VUVANTSUMME"] = " ".PadRight(2 ); 
         dwReturn["VUVWOHER"] = " ".PadRight(1 ); 
         dwReturn["VUVWAEHRSL"] = " ".PadRight(3 ); 
         dwReturn["VUVKURS"] = " ".PadRight(0 ); 
         dwReturn["VUVBETRAG"] = " ".PadRight(0 ); 
         dwReturn["VUVFILLER"] = " ".PadRight(61 ); 
         dwReturn["VUVAENZL"] = " ".PadRight(0 ); 
         dwReturn["VUVAENB"] = " ".PadRight(8 ); 
         dwReturn["VUVNEUB"] = " ".PadRight(8 ); 
         dwReturn["VUVAEND"] = " ".PadRight(0 ); 
         dwReturn["VUVNEUD"] = " ".PadRight(0 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapVUMSV(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveVUMSV(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryVUMSV(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapVUMSV(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertVUMSV(dwLocal, ITXDBVERSION);
            }
            UpdateVUMSV(dwLocal);
        }
        public void InsertVUMSV(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO VUMSV(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryVUMSV(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM VUMSV WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM VUMSV  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "VUMSV";
            Return = Result;
            return Return;
        }
        public void DeleteVUMSV(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM VUMSV   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateVUMSV(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE VUMSV SET "
                    +"VUVMANDANT= :VUVMANDANT,"
                    +"VUVRENR= :VUVRENR,"
                    +"VUVREPOS= :VUVREPOS,"
                    +"VUVSPLPOS= :VUVSPLPOS,"
                    +"VUVVERTNR= :VUVVERTNR,"
                    +"VUVKORRKZ= :VUVKORRKZ,"
                    +"VUVDRUCKKZ= :VUVDRUCKKZ,"
                    +"VUVSPERRKZ= :VUVSPERRKZ,"
                    +"VUVPVTYP= :VUVPVTYP,"
                    +"VUVPVVAR= :VUVPVVAR,"
                    +"VUVBASISBTR= :VUVBASISBTR,"
                    +"VUVSTDPV= :VUVSTDPV,"
                    +"VUVSONDPV= :VUVSONDPV,"
                    +"VUVERSTPV= :VUVERSTPV,"
                    +"VUVMENGENPV= :VUVMENGENPV,"
                    +"VUVMEEHPV= :VUVMEEHPV,"
                    +"VUVPRNBTL= :VUVPRNBTL,"
                    +"VUVABZUG= :VUVABZUG,"
                    +"VUVVPROV= :VUVVPROV,"
                    +"VUVABRDAT= :VUVABRDAT,"
                    +"VUVKUNDNR= :VUVKUNDNR,"
                    +"VUVVB= :VUVVB,"
                    +"VUVVG= :VUVVG,"
                    +"VUVABRVON= :VUVABRVON,"
                    +"VUVABRBIS= :VUVABRBIS,"
                    +"VUVFOBBASIS= :VUVFOBBASIS,"
                    +"VUVANTEIL= :VUVANTEIL,"
                    +"VUVANTSUMME= :VUVANTSUMME,"
                    +"VUVWOHER= :VUVWOHER,"
                    +"VUVWAEHRSL= :VUVWAEHRSL,"
                    +"VUVKURS= :VUVKURS,"
                    +"VUVBETRAG= :VUVBETRAG,"
                    +"VUVFILLER= :VUVFILLER,"
                    +"VUVAENZL= :VUVAENZL,"
                    +"VUVAENB= :VUVAENB,"
                    +"VUVNEUB= :VUVNEUB,"
                    +"VUVAEND= :VUVAEND,"
                    +"VUVNEUD= :VUVNEUD,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("VUVMANDANT", OracleType.NVarChar).Value = dwData["VUVMANDANT"].ToString(); 
          or1.Parameters.Add("VUVRENR", OracleType.NVarChar).Value = dwData["VUVRENR"].ToString(); 
          or1.Parameters.Add("VUVREPOS", OracleType.NVarChar).Value = dwData["VUVREPOS"].ToString(); 
          or1.Parameters.Add("VUVSPLPOS", OracleType.NVarChar).Value = dwData["VUVSPLPOS"].ToString(); 
          or1.Parameters.Add("VUVVERTNR", OracleType.NVarChar).Value = dwData["VUVVERTNR"].ToString(); 
          or1.Parameters.Add("VUVKORRKZ", OracleType.NVarChar).Value = dwData["VUVKORRKZ"].ToString(); 
          or1.Parameters.Add("VUVDRUCKKZ", OracleType.NVarChar).Value = dwData["VUVDRUCKKZ"].ToString(); 
          or1.Parameters.Add("VUVSPERRKZ", OracleType.NVarChar).Value = dwData["VUVSPERRKZ"].ToString(); 
          or1.Parameters.Add("VUVPVTYP", OracleType.NVarChar).Value = dwData["VUVPVTYP"].ToString(); 
          or1.Parameters.Add("VUVPVVAR", OracleType.NVarChar).Value = dwData["VUVPVVAR"].ToString(); 
          or1.Parameters.Add("VUVBASISBTR", OracleType.NVarChar).Value = dwData["VUVBASISBTR"].ToString(); 
          or1.Parameters.Add("VUVSTDPV", OracleType.NVarChar).Value = dwData["VUVSTDPV"].ToString(); 
          or1.Parameters.Add("VUVSONDPV", OracleType.NVarChar).Value = dwData["VUVSONDPV"].ToString(); 
          or1.Parameters.Add("VUVERSTPV", OracleType.NVarChar).Value = dwData["VUVERSTPV"].ToString(); 
          or1.Parameters.Add("VUVMENGENPV", OracleType.NVarChar).Value = dwData["VUVMENGENPV"].ToString(); 
          or1.Parameters.Add("VUVMEEHPV", OracleType.NVarChar).Value = dwData["VUVMEEHPV"].ToString(); 
          or1.Parameters.Add("VUVPRNBTL", OracleType.NVarChar).Value = dwData["VUVPRNBTL"].ToString(); 
          or1.Parameters.Add("VUVABZUG", OracleType.NVarChar).Value = dwData["VUVABZUG"].ToString(); 
          or1.Parameters.Add("VUVVPROV", OracleType.NVarChar).Value = dwData["VUVVPROV"].ToString(); 
          or1.Parameters.Add("VUVABRDAT", OracleType.NVarChar).Value = dwData["VUVABRDAT"].ToString(); 
          or1.Parameters.Add("VUVKUNDNR", OracleType.NVarChar).Value = dwData["VUVKUNDNR"].ToString(); 
          or1.Parameters.Add("VUVVB", OracleType.NVarChar).Value = dwData["VUVVB"].ToString(); 
          or1.Parameters.Add("VUVVG", OracleType.NVarChar).Value = dwData["VUVVG"].ToString(); 
          or1.Parameters.Add("VUVABRVON", OracleType.NVarChar).Value = dwData["VUVABRVON"].ToString(); 
          or1.Parameters.Add("VUVABRBIS", OracleType.NVarChar).Value = dwData["VUVABRBIS"].ToString(); 
          or1.Parameters.Add("VUVFOBBASIS", OracleType.NVarChar).Value = dwData["VUVFOBBASIS"].ToString(); 
          or1.Parameters.Add("VUVANTEIL", OracleType.NVarChar).Value = dwData["VUVANTEIL"].ToString(); 
          or1.Parameters.Add("VUVANTSUMME", OracleType.NVarChar).Value = dwData["VUVANTSUMME"].ToString(); 
          or1.Parameters.Add("VUVWOHER", OracleType.NVarChar).Value = dwData["VUVWOHER"].ToString(); 
          or1.Parameters.Add("VUVWAEHRSL", OracleType.NVarChar).Value = dwData["VUVWAEHRSL"].ToString(); 
          or1.Parameters.Add("VUVKURS", OracleType.NVarChar).Value = dwData["VUVKURS"].ToString(); 
          or1.Parameters.Add("VUVBETRAG", OracleType.NVarChar).Value = dwData["VUVBETRAG"].ToString(); 
          or1.Parameters.Add("VUVFILLER", OracleType.NVarChar).Value = dwData["VUVFILLER"].ToString(); 
          or1.Parameters.Add("VUVAENZL", OracleType.NVarChar).Value = dwData["VUVAENZL"].ToString(); 
          or1.Parameters.Add("VUVAENB", OracleType.NVarChar).Value = dwData["VUVAENB"].ToString(); 
          or1.Parameters.Add("VUVNEUB", OracleType.NVarChar).Value = dwData["VUVNEUB"].ToString(); 
          or1.Parameters.Add("VUVAEND", OracleType.NVarChar).Value = dwData["VUVAEND"].ToString(); 
          or1.Parameters.Add("VUVNEUD", OracleType.NVarChar).Value = dwData["VUVNEUD"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
